package com.sann.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sann.cms.entity.Banner;
import com.sann.cms.mapper.BannerMapper;
import com.sann.cms.service.BannerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sann.common.utils.R;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 首页banner表 服务实现类
 * </p>
 *
 * @author sann
 * @since 2021-05-04
 */
@Service
public class BannerServiceImpl extends ServiceImpl<BannerMapper, Banner> implements BannerService {


    /**
     * Redis中存的键名 = banner::indexList
     * 当key = "'indexList'"没配置，key=banner
     * 注意：key = "'indexList'"中记得加单引号''
     */
    @Cacheable(value = "banner", key = "'indexList'")
    @Override
    public List<Banner> getList() {
        QueryWrapper<Banner> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");// 按照id逆序排序
        queryWrapper.last("limit 5");//取前5条
        return this.baseMapper.selectList(queryWrapper);
    }
}
